﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NimbleTextKeygen
{
    public static class Defaults
    {
        internal static Snippet[] GetDefaultBuiltinFunctions()
        {
            return new Snippet[] { new Snippet()
            {
                Name = "To UPPER Case ",
                Value = "<% $0.toUpperCase() %>",
                TooltipText = "Convert text to all capitals"
            }, new Snippet()
            {
                Name = "To lower Case",
                Value = "<% $0.toLowerCase() %>",
                TooltipText = "Convert text to lowercase"
            }, new Snippet()
            {
                Name = "To Title Case",
                Value = "<% $0.toTitleCase() %>",
                TooltipText = "Convert Text So that Every Word Starts With A Capital"
            }, new Snippet()
            {
                Name = "To PascalCase",
                Value = "<% $0.toPascalCase() %>",
                TooltipText = "Join separate words into one PascalCaseWord"
            }, new Snippet()
            {
                Name = "To camelCase",
                Value = "<% $0.toCamelCase() %>",
                TooltipText = "Join separate words into one camelCaseWord"
            }, new Snippet()
            {
                Name = "To sentence case",
                Value = "<% $0.toSentenceCase() %>",
                TooltipText = "Capitalize the first letter of the first word and make the rest lower case."
            }, new Snippet()
            {
                Name = "To_snake_case",
                Value = "<% $0.toSnakeCase() %>",
                TooltipText = "Join separate words with _ underscores"
            }, new Snippet()
            {
                Name = "To-kebab-case",
                Value = "<% $0.toKebabCase() %>",
                TooltipText = "Join separate words with - hyphens"
            }, new Snippet()
            {
                Name = "To words (from PascalCase etc.)",
                Value = "<% $0.toWords() %>",
                TooltipText = "Split WordsJoinedUsingCapitals into separate words"
            }, new Snippet()
            {
                Name = "Reverse",
                Value = "<% $0.reverse() %>",
                TooltipText = "Reverse the letters, i.e. Hello -> olleH"
            }, new Snippet()
            {
                Name = "Replace",
                Value = "<% $row.replace(/Hello/g,'Goodbye') %>",
                TooltipText = "Replace one substring with another"
            }, new Snippet()
            {
                Name = "Replace (using regex)",
                Value = "<% $row.replace(/[:;()+]/gm,' ') %>",
                TooltipText = "Replace regex matches with a substring"
            }, new Snippet()
            {
                Name = "Trim",
                Value = "<% $0.trim() %>",
                TooltipText = "Remove leading and trailing white space"
            }, new Snippet()
            {
                Name = "Left Trim",
                Value = "<% $0.ltrim() %>",
                TooltipText = "Remove leading white space"
            }, new Snippet()
            {
                Name = "Right Trim",
                Value = "<% $0.rtrim() %>",
                TooltipText = "Remove trailing white space"
            }, new Snippet()
            {
                Name = "Html Encode",
                Value = "<% $0.htmlEncode() %>",
                TooltipText = "Turn < into &gt;, etc."
            }, new Snippet()
            {
                Name = "Html Decode",
                Value = "<% $0.htmlDecode() %>",
                TooltipText = "Turn &gt; into >  etc."
            }, new Snippet()
            {
                Name = "Url Encode",
                Value = "<% $0.urlEncode() %>",
                TooltipText = "Turn ' ' into %20, etc."
            }, new Snippet()
            {
                Name = "Url Decode",
                Value = "<% $0.urlDecode() %>",
                TooltipText = "Turn %20 into ' ', etc."
            }, new Snippet()
            {
                Name = "XML Encode",
                Value = "<% $0.xmlEncode() %>",
                TooltipText = "Turn < into &gt;, etc."
            }, new Snippet()
            {
                Name = "XML Decode",
                Value = "<% $0.xmlDecode() %>",
                TooltipText = "Turn &gt; into >  etc."
            }, new Snippet()
            {
                Name = "Split",
                Value = "<% $0.split(' ')[0] %>",
                TooltipText = "Separate a string into an array"
            }, new Snippet()
            {
                Name = "Char At",
                Value = "<% $row.charAt(3) %>",
                TooltipText = "Find the nth character"
            }, new Snippet()
            {
                Name = "Index Of",
                Value = "<% $row.indexOf(',') %>",
                TooltipText = "Find the first instance of a substring"
            }, new Snippet()
            {
                Name = "Last Index Of",
                Value = "<% $row.lastIndexOf(',') %>",
                TooltipText = "Find the last instance of a substring"
            }, new Snippet()
            {
                Name = "Slice",
                Value = "<% $row.slice(2,5) %>",
                TooltipText = "Return the text between 2 positions"
            }, new Snippet()
            {
                Name = "Substr",
                Value = "<% $row.substr(2,3) %>",
                TooltipText = "Return a substring starting from one position, of a given length"
            }, new Snippet()
            {
                Name = "Left",
                Value = "<% $0.left(2) %>",
                TooltipText = "Return some characters from the left of the string"
            }, new Snippet()
            {
                Name = "Right",
                Value = "<% $0.right(2) %>",
                TooltipText = "Return some characters from the right of the string"
            }, new Snippet()
            {
                Name = "LPad",
                Value = "<% $0.lpad(10, '0') %>",
                TooltipText = "Pad a string to a fixed width by adding chracters on the left"
            }, new Snippet()
            {
                Name = "RPad",
                Value = "<% $0.rpad(10, ' ') %>",
                TooltipText = "Pad a string to a fixed width by adding characters on the right"
            }, new Snippet()
            {
                Name = "Format Date",
                Value = "<% $0.dateFormat('dd mmm yyyy') %>",
                TooltipText = "Turn an ISO date into any format you wish (see Help for specifics)"
            }, new Snippet()
            {
                Name = "Word Wrap",
                Value = "<% $0.wordWrap(80) %>",
                TooltipText = "Wrap long lines, on word breaks, maximum 80 characters"
            }, new Snippet()
            {
                Name = "Calculate",
                Value = "$ONCE<% \r\ncalculate(\r\n  $('txtData').value, /* data */\r\n  '$dollar;0',        /* pattern */\r\n  '',                 /* filter */\r\n  '\\n',               /* row separator */\r\n  ','                 /* column separator */\r\n  , { numRows : 0}) %>",
                TooltipText = "Perform complete pattern substitution on a substring."
            } };
        }

        internal static Snippet[] GetDefaultKeywords()
        {
            return new Snippet[] { new Snippet()
            {
                Name = "Handy keywords...",
                Value = null
            }, new Snippet()
            {
                Name = "$0 (the first column)",
                Value = "$0"
            }, new Snippet()
            {
                Name = "$1 (the second column, etc)",
                Value = "$1"
            }, new Snippet()
            {
                Name = "$h0 (the first heading)",
                Value = "$h0"
            }, new Snippet()
            {
                Name = "$h1 (the second heading, etc)",
                Value = "$h1"
            }, new Snippet()
            {
                Name = "$-1 (the last column)",
                Value = "$-1"
            }, new Snippet()
            {
                Name = "$-2 (second last column, etc)",
                Value = "$-2"
            }, new Snippet()
            {
                Name = "$row (the entire row)",
                Value = "$row"
            }, new Snippet()
            {
                Name = "$rowNum (starts at zero)",
                Value = "$rowNum"
            }, new Snippet()
            {
                Name = "$rowNumOne (starts at one)",
                Value = "$rowNumOne"
            }, new Snippet()
            {
                Name = "$numRows",
                Value = "$numRows"
            }, new Snippet()
            {
                Name = "$numFields",
                Value = "$numFields"
            }, new Snippet()
            {
                Name = "$ONCE (delimits a one off section)",
                Value = "$ONCE"
            }, new Snippet()
            {
                Name = "$EACH (delimits a for each section)",
                Value = "$EACH"
            }, new Snippet()
            {
                Name = "$EACH+ (for each section, skipping first row)",
                Value = "$EACH+"
            }, new Snippet()
            {
                Name = "$dollar; (literal '$')",
                Value = "$dollar;"
            }, new Snippet()
            {
                Name = "$percent; (literal '%')",
                Value = "$percent;"
            }, new Snippet()
            {
                Name = "$lt; (literal '<')",
                Value = "$lt;"
            }, new Snippet()
            {
                Name = "$gt; (literal '>')",
                Value = "$gt;"
            } };
        }

        public static CurrentSession GetDefaultSession(Icon icon, Settings settings, float factor = 1f)
        {
            return new CurrentSession(icon, settings, factor)
            {
                Name = "",
                DataName = "",
                PatternName = "",
                ResultsName = ""
            };
        }

        public static Settings GetDefaultSettings()
        {
            return new Settings()
            {
                ColumnDelimiter = ",",
                RowDelimiter = "\r\n",
                InputData = "Lumbergh, Bill, Initech\r\nWaddams, Milton, Initech\r\nGibbons, Peter, Initech\r\nBolton, Michael, Initech",
                InputPattern = "To: $1.$0@$2.com \r\nHello $1 $0\r\nI'm sorry to inform you of a terrible accident at $2.\r\n---",
                DataHistory = new MRUHistory(),
                PatternHistory = new MRUHistory(),
                ResultsHistory = new MRUHistory(),
                TrimFields = new bool?(true),
                AutoPreview = true,
                TreatConsecutiveFieldDelimitersAsOne = false,
                UseQualifiers = false,
                Qualifier = "\"",
                OutputNewLineAfterEachRow = new bool?(true),
                IgnoreEmptyRows = new bool?(true),
                CheckForUpdates = false,
                SessionHistory = new MRUHistory(),
                NumRows = 6,
                EulaAccepted = false,
                LogFilename = Log.DefaultLogFilename,
                Snippets = new List<Snippet>(Defaults.GetDefaultSnippets()),
                DataSortSettings = new SortSettings(),
                ResultSortSettings = new SortSettings(),
                ColumnDelimiterIsRegex = false,
                RowDelimiterIsRegex = false,
                NormalizeToUnixLineEndings = new bool?(false),
                Theme = "System Theme",
                WindowState = new FormWindowState?(FormWindowState.Maximized)
            };
        }

        internal static Snippet[] GetDefaultSnippets()
        {
            return new Snippet[] { new Snippet()
            {
                Name = "'If' example",
                Value = "<% if ($1.toUpperCase() == 'CAT') { 'AHA! '; } else {''} %>",
                VersionUpdated = "2.9.1.36018"
            }, new Snippet()
            {
                Name = "'Unless first row'",
                Value = "<% if ($rownum != 0) { 'AND '; } else {'    '} %>$row",
                VersionUpdated = "2.9.1.36018"
            }, new Snippet()
            {
                Name = "'Unless final row'",
                Value = "<% if ($rownumOne != $numrows) { ','; } %>$row",
                VersionUpdated = "2.9.1.36018"
            }, new Snippet()
            {
                Name = "C#: Properties (explicit)",
                Value = "private $0 <% $1.toCamelCase() %>;\r\n$ONCE\r\n\r\n$EACH\r\npublic $0 <% $1.toPascalCase() %> {\r\n  get { return <% $1.toCamelCase() %>; }\r\n  set { <% $1.toCamelCase() %> = value; }\r\n}",
                VersionUpdated = "2.9.1.36018"
            }, new Snippet()
            {
                Name = "C#: Properties (INotifyPropertyChanged)",
                Value = "        private $0 <% $1.toCamelCase() %>;\r\n        public $0 <% $1.toPascalCase() %>\r\n        {\r\n            get { return <% $1.toCamelCase() %>; }\r\n            private set { <% $1.toCamelCase() %> = value;\r\n            NotifyOfChange(\"<% $1.toPascalCase() %>\");\r\n            }\r\n        }$ONCE\r\n        public event PropertyChangedEventHandler PropertyChanged;\r\n\r\n        private void NotifyOfChange(string propertyName)\r\n        {\r\n            if (this.PropertyChanged != null)\r\n            {\r\n                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));\r\n            }\r\n        }\r\n",
                VersionUpdated = "2.9.1.36018"
            }, new Snippet()
            {
                Name = "HTML: Table (plain)",
                Value = "$ONCE\r\n<table>\r\n$EACH\r\n  <tr>\r\n    <td>$row</td>\r\n  </tr>\r\n$ONCE\r\n</table>",
                VersionUpdated = "2.9.1.36018"
            }, new Snippet()
            {
                Name = "HTML: Table (with headings)",
                Value = "$ONCE\r\n<table>\r\n <thead>\r\n   <tr>\r\n     <th>$0</th>\r\n     <th>$1</th>\r\n   </tr>\r\n </thead>\r\n <tbody>\r\n$EACH+\r\n  <tr>\r\n    <td>$0</td>\r\n    <td>$1</td>\r\n  </tr>\r\n$ONCE\r\n </tbody>\r\n</table>",
                VersionUpdated = "2.9.1.36018"
            }, new Snippet()
            {
                Name = "HTML: Unordered List",
                Value = "$ONCE<ul>\r\n$EACH  <li>$row</li>\r\n$ONCE</ul>",
                VersionUpdated = "2.9.1.36018"
            }, new Snippet()
            {
                Name = "HTML: Ordered List",
                Value = "$ONCE<ol>\r\n$EACH  <li>$row</li>\r\n$ONCE</ol>",
                VersionUpdated = "2.9.1.36018"
            }, new Snippet()
            {
                Name = "SQL: 'in' statement",
                Value = "$ONCE\r\nin \r\n($EACH'$0'<% if ($rownumOne != $numrows) { ','; } else {')'} %>",
                VersionUpdated = "2.9.1.36018"
            }, new Snippet()
            {
                Name = "Markdown Table generator",
                Value = "$ONCE\r\n| <% ($row).split(fieldDelim).map(function(v) { return v;}).join(' | '); %> |\r\n|-<% ($row).split(fieldDelim).map(function(v) { return v.replace(/./g,'-');}).join('-|-'); %>-|\r\n$EACH+| <% ($row).split(fieldDelim).map(function(v) { return v;}).join(' | '); %> |\r\n",
                VersionUpdated = "3.0.0.0"
            }, new Snippet()
            {
                Name = "Markdown TOC generator",
                Value = "<% \r\n// Given just the heading from a markdown document. Tip: use 'Where Clause' to filter for headings only with: /^( )*#+/.test($row)\r\n\r\n// the heading:\r\n$row.trim().replace(/^(#)(#*)( )*(.*)/g, \r\n    function(fullMatch, firstHashCharacter, remainingHashes, optionalSpaceBetweenHashAndHeading, headingItself) { \r\n      return remainingHashes.replace(/#/g, '  ') + \r\n             '- [' + headingItself + ']';}) %>(#<%\r\n// slugify the heading for an on-page link:\r\n$row.trim().replace(/^#+/g,'').trim().replace(/[ ,()!:\\\\]/g,'-').replace(/[-]+/g,'-').toLowerCase() \r\n%>)\r\n",
                VersionUpdated = "3.0.0.0"
            }, new Snippet()
            {
                Name = "Unsmarten text",
                Value = "<% $row\r\n   .replace( /\\u2018|\\u2019|\\u201A/g, \"'\")\r\n   .replace( /\\u201c|\\u201d|\\u201e/g, '\"')\r\n   .replace( /\\u02C6/g, '^')\r\n   .replace( /\\u2039/g, '<')\r\n   .replace( /\\u203A/g, '>')\r\n   .replace( /\\u2013/g, '-')\r\n   .replace( /\\u2014/g, '--')\r\n   .replace( /\\u2026/g, '...')\r\n   .replace( /\\u00A9/g, '(c)')\r\n   .replace( /\\u00AE/g, '(r)')\r\n   .replace( /\\u2122/g, 'TM')\r\n   .replace( /\\u00BC/g, '1/4')\r\n   .replace( /\\u00BD/g, '1/2')\r\n   .replace( /\\u00BE/g, '3/4')\r\n   .replace(/[\\u02DC|\\u00A0]/g, ' ')\r\n%>",
                VersionUpdated = "3.0.0.0"
            } };
        }
    }
}
